﻿using OASystem.DAL;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;

namespace OASystem.BLL
{
    public class BaseService<T> where T : class
    {
        private BaseRepository<T> baseRepository = new BaseRepository<T>();

        //添加单条记录
        public virtual bool Add(T entily)
        {

            return baseRepository.Add(entily);

        }

        //添加多条记录
        public virtual bool AddList(List<T> entily)
        {
            return baseRepository.AddRange(entily);
        }

        //删除
        public virtual bool DELETE(T entily)
        {
            return baseRepository.Delete(entily);
        }

        //删除多个
        public virtual bool BDELETE(List<T> entiles)
        {
            return baseRepository.BatchDelete(entiles);
        }

        //根据id删除
        public bool BatchDELETE(params int[] entiles)
        {
            return baseRepository.BatchDeleteById(entiles);
        }
        //修改
        public virtual bool Update(T entily)
        {

            return baseRepository.Update(entily);
        }

        //查询一个集合
        public virtual List<T> QueryList(Expression<Func<T, bool>> lambdaExpression)
        {
            return baseRepository.QueryList(lambdaExpression);
        }

        //查询一个对象，如果没有返回null

        public virtual T Query(Expression<Func<T, bool>> lambdaExpression)
        {
            return baseRepository.Query(lambdaExpression);
        }

        public virtual bool Exists(Expression<Func<T, bool>> lambdaExpression)
        {
            return baseRepository.Exists(lambdaExpression);
        }

        //分页查询
        public virtual List<T> QuerypageList<S>(int pageIndex, int pageSize, Expression<Func<T, bool>> wheredma, Expression<Func<T, S>> orderbyLamba, out int count, bool isAc = true)
        {
            return baseRepository.QueryPageList(pageIndex, pageSize, wheredma, orderbyLamba, out count, isAc);
        }
    }
}

